//	AboutForm.cs - About Dialog
//  Copyright (C) Microsoft Corporation. All rights reserved.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;
using visAd.ExceptionHandler;

namespace visAd.ServerDataAddIn
{
	/// <summary>
	/// Summary description for AboutForm.
	/// </summary>
	public class AboutForm : Form
	{
		#region controls

		private System.Windows.Forms.Label labelTitle;
		private System.Windows.Forms.Label labelDisclaimer;
		private System.Windows.Forms.Button buttonOK;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.LinkLabel linkLabelMarketingMessage1;
        string url;

		#endregion

        private const string mClassName = "AboutForm";
		
		#region construction / destruction

		/// <summary>
		/// Default Constructor
		/// </summary>
		public AboutForm()
		{
			// Required for Windows Form Designer support
			InitializeComponent();

            this.url = "http://www.visiotoolbox.com/";

			// load the resources for this form
			UpdateFormResourceStrings();
		}

		#endregion

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm));
            this.labelTitle = new System.Windows.Forms.Label();
            this.labelDisclaimer = new System.Windows.Forms.Label();
            this.buttonOK = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.linkLabelMarketingMessage1 = new System.Windows.Forms.LinkLabel();
            this.SuspendLayout();
            // 
            // labelTitle
            // 
            resources.ApplyResources(this.labelTitle, "labelTitle");
            this.labelTitle.Name = "labelTitle";
            // 
            // labelDisclaimer
            // 
            resources.ApplyResources(this.labelDisclaimer, "labelDisclaimer");
            this.labelDisclaimer.Name = "labelDisclaimer";
            // 
            // buttonOK
            // 
            resources.ApplyResources(this.buttonOK, "buttonOK");
            this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.buttonOK.Name = "buttonOK";
            this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
            // 
            // groupBox1
            // 
            resources.ApplyResources(this.groupBox1, "groupBox1");
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.TabStop = false;
            // 
            // groupBox2
            // 
            resources.ApplyResources(this.groupBox2, "groupBox2");
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.TabStop = false;
            // 
            // linkLabelMarketingMessage1
            // 
            resources.ApplyResources(this.linkLabelMarketingMessage1, "linkLabelMarketingMessage1");
            this.linkLabelMarketingMessage1.Name = "linkLabelMarketingMessage1";
            this.linkLabelMarketingMessage1.TabStop = true;
            this.linkLabelMarketingMessage1.UseCompatibleTextRendering = true;
            this.linkLabelMarketingMessage1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabelMarketingMessage1_LinkClicked);
            // 
            // AboutForm
            // 
            this.AcceptButton = this.buttonOK;
            resources.ApplyResources(this, "$this");
            this.CancelButton = this.buttonOK;
            this.ControlBox = false;
            this.Controls.Add(this.linkLabelMarketingMessage1);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.buttonOK);
            this.Controls.Add(this.labelDisclaimer);
            this.Controls.Add(this.labelTitle);
            this.Controls.Add(this.groupBox2);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "AboutForm";
            this.ShowInTaskbar = false;
            this.ResumeLayout(false);

		}

		#endregion

		/// <summary>
		/// Loads the strings for this form.
		/// </summary>
		private void UpdateFormResourceStrings()
		{
			labelTitle.Text = labelTitle.Text.Replace("{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
		}

		/// <summary>
		/// Close this form.
		/// </summary>
		/// <param name="sender">
		/// </param>
		/// <param name="e">
		/// </param>
		private void buttonOK_Click(
			object sender,
			System.EventArgs e)
		{
			this.DialogResult = DialogResult.OK;
		}

        /// <summary>
        /// Reads path of default browser from registry
        /// </summary>
        /// <returns></returns>
        private static string GetDefaultBrowserPath()
        {

            string key = @"htmlfile\shell\open\command";

            RegistryKey registryKey =

            Registry.ClassesRoot.OpenSubKey(key, false);

            // get default browser path
            return ((string)registryKey.GetValue(null, null)).Split('"')[1];

        }


		/// <summary>
		/// Navagate the like to the web site.
		/// </summary>
		/// <param name="sender">
		/// </param>
		/// <param name="e">
		/// </param>
		private void linkLabelMarketingMessage1_LinkClicked(
			object sender,
			System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{			
            // code to open the URL
            try
            {
                string defaultBrowserPath = GetDefaultBrowserPath();

                // launch default browser
                Process.Start(defaultBrowserPath, url);
            }
            catch (Exception ex)
            {
                //Exception from current function
                throw new vaCustomException(ex, mClassName, "linkLabelMarketingMsg1_Link");
            }
		}
	}
}
